import { createApp } from 'vue'
import { createPinia, Pinia, PiniaPlugin } from 'pinia'
import { createPersistedState } from 'pinia-persistedstate-plugin';

declare module 'pinia' {
  export interface PiniaCustomProperties {
    appInstance: ReturnType<typeof createApp>
  }
}

/**
 * 安装pinia插件
 * @param app 要安装的vue应用
 */
function installPinia (app: ReturnType<typeof createApp>) {
  const pinia = createPinia()
  pinia.use((context) => {
    context.store.appInstance = app
  })
  pinia.use(createPersistedState())
  app.use(pinia)
}

export default installPinia
